package org.korifey.ffbdd.impl;

public class BitvectorConst {
	
	/**
	 * Convert negative index in case terminals into real index. Otherway index stays the same.
	 * @param index
	 * @return
	 */
	public static int fakeIndex(int index) {
		return  (index < 0) ? BitvectorConst.MAXNODES + index : index;
	}
	
	/**
	 * Convert real array index to negative index in case of terminals. Otherway index stays the same.
	 * @param index
	 * @return
	 */
	public static int realIndex(int index) {		
		return  (index > BitvectorConst.MAXNODES - BitvectorConst.MAXTERMINALS) ? index - BitvectorConst.MAXNODES : index;
	}
	
	public static int realVar(int var) {
		if (var >= MAXVAR) return MAXFAKEVAR - var;
		else return var;
	}
	
	public static boolean isMarked(int var) {
		return (var >= MAXVAR);
	}
	
	public static int makeFakeVar(int realVar, boolean mark) {
		if (mark) return MAXFAKEVAR - realVar;
		else return realVar;  
	}

	public static final int MAXNODES = 256 * 256 * 256 * 16; //3.5 byte for node index
	public static final int MAXTERMINALS = 256 * 256; // 2 byte for terminals
	public static final int MAXNONTERMINALS = MAXNODES  - MAXTERMINALS; // 3.5 byte - 2 byte
	public static final int MAXFAKEVAR = 256 * 256; // 2 byte storage
	public static final int MAXVAR = MAXFAKEVAR / 2; // negative variables are for marks
	public static final int MAXOPS = 256*16; //1,5 bytes for op code
}
